package com.hl.controller.huiyuan;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.hl.domain.FundFlow;
import com.hl.service.IFundFlowService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 会员资金Controller
 * 
 * @author vv
 * @date 2025-08-05
 */
@RestController
@RequestMapping("/flow")
public class FundFlowController extends BaseController
{
    @Autowired
    private IFundFlowService fundFlowService;

    /**
     * 查询会员资金列表
     */
    @RequiresPermissions("huiyuan:flow:list")
    @GetMapping("/list")
    public TableDataInfo list(FundFlow fundFlow)
    {
        startPage();
        List<FundFlow> list = fundFlowService.selectFundFlowList(fundFlow);
        return getDataTable(list);
    }

    /**
     * 导出会员资金列表
     */
    @RequiresPermissions("huiyuan:flow:export")
    @Log(title = "会员资金", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, FundFlow fundFlow)
    {
        List<FundFlow> list = fundFlowService.selectFundFlowList(fundFlow);
        ExcelUtil<FundFlow> util = new ExcelUtil<FundFlow>(FundFlow.class);
        util.exportExcel(response, list, "会员资金数据");
    }

    /**
     * 获取会员资金详细信息
     */
    @RequiresPermissions("huiyuan:flow:query")
    @GetMapping(value = "/{flowId}")
    public AjaxResult getInfo(@PathVariable("flowId") String flowId)
    {
        return success(fundFlowService.selectFundFlowByFlowId(flowId));
    }
    /**
     * 获取会员最新余额
     */
    @RequiresPermissions("huiyuan:flow:query")
    @GetMapping(value = "/balance/{memberId}")
    public AjaxResult getBalanceAfter(@PathVariable("memberId") Long memberId)
    {
        return success(fundFlowService.selectLatestBalanceAfter(memberId));
    }
    /**
     * 新增会员资金
     */
    @RequiresPermissions("huiyuan:flow:add")
    @Log(title = "会员资金", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody FundFlow fundFlow)
    {
        return toAjax(fundFlowService.insertFundFlow(fundFlow));
    }

    /**
     * 修改会员资金
     */
    @RequiresPermissions("huiyuan:flow:edit")
    @Log(title = "会员资金", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody FundFlow fundFlow)
    {
        return toAjax(fundFlowService.updateFundFlow(fundFlow));
    }

    /**
     * 删除会员资金
     */
    @RequiresPermissions("huiyuan:flow:remove")
    @Log(title = "会员资金", businessType = BusinessType.DELETE)
	@DeleteMapping("/{flowIds}")
    public AjaxResult remove(@PathVariable String[] flowIds)
    {
        return toAjax(fundFlowService.deleteFundFlowByFlowIds(flowIds));
    }
}
